

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>ccqw.filePicker &mdash; CCQW 0.1.1 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/sidebar.js"></script>
    <link rel="top" title="CCQW 0.1.1 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">CCQW 0.1.1 documentation</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for ccqw.filePicker</h1><div class="highlight"><pre>
<span class="c"># -*- coding: utf-8 -*-</span>
<span class="sd">&quot;&quot;&quot; A class to choose files interactively.</span>

<span class="sd">    :Author:</span>
<span class="sd">      - 20091202-20100321 Nicola Creati</span>
<span class="sd">      - 20111202-20120214 Roberto Vidmar</span>

<span class="sd">    :Revision:  $Revision: 52 $</span>
<span class="sd">                $Date: 2012-11-12 10:07:15 +0100 (Mon, 12 Nov 2012) $</span>

<span class="sd">    :Copyright: 2011-2012</span>
<span class="sd">                Nicola Creati &lt;ncreati@inogs.it&gt;</span>
<span class="sd">                Roberto Vidmar &lt;rvidmar@inogs.it&gt;</span>

<span class="sd">    :License: MIT/X11 License (see :download:`license.txt</span>
<span class="sd">                               &lt;../../license.txt&gt;`)</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">os</span>

<span class="kn">from</span> <span class="nn">qtCompat</span> <span class="kn">import</span> <span class="n">Signal</span><span class="p">,</span> <span class="n">Qt</span><span class="p">,</span> <span class="n">QtCore</span><span class="p">,</span> <span class="n">QtGui</span><span class="p">,</span> <span class="n">getOpenFileName</span><span class="p">,</span> <span class="n">getSaveFileName</span>
<span class="n">QCA</span> <span class="o">=</span> <span class="n">QtCore</span><span class="o">.</span><span class="n">QCoreApplication</span>

<span class="kn">from</span> <span class="nn">fileBrowser</span> <span class="kn">import</span> <span class="n">FileBrowser</span>

<span class="c">#==============================================================================</span>
<div class="viewcode-block" id="TinyButton"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.TinyButton">[docs]</a><span class="k">class</span> <span class="nc">TinyButton</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QPushButton</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot; A QPushButton with a size fitted to the button label</span>
<span class="sd">  &quot;&quot;&quot;</span>
<div class="viewcode-block" id="TinyButton.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.TinyButton.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">parent</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new TinyButton instance.</span>

<span class="sd">      :param label: label to put on the tiny button</span>
<span class="sd">      :type label: string</span>
<span class="sd">      :param parent: parent widget</span>
<span class="sd">      :type parent: QtGui widget</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">TinyButton</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="n">parent</span><span class="p">)</span>

    <span class="n">textWidth</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">fontMetrics</span><span class="p">()</span><span class="o">.</span><span class="n">boundingRect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="p">())</span><span class="o">.</span><span class="n">width</span><span class="p">()</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setMaximumWidth</span><span class="p">(</span><span class="n">textWidth</span> <span class="o">+</span> <span class="mi">12</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setFocusPolicy</span><span class="p">(</span><span class="n">Qt</span><span class="o">.</span><span class="n">NoFocus</span><span class="p">)</span>

<span class="c">#==============================================================================</span></div></div>
<div class="viewcode-block" id="FileValidator"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.FileValidator">[docs]</a><span class="k">class</span> <span class="nc">FileValidator</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QValidator</span><span class="p">):</span>
<div class="viewcode-block" id="FileValidator.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.FileValidator.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new FileValidator instance.</span>

<span class="sd">      :param parent: parent widget</span>
<span class="sd">      :type parent: QtGui widget</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">FileValidator</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="FileValidator.validate"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.FileValidator.validate">[docs]</a>  <span class="k">def</span> <span class="nf">validate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">l</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Reimplementation of the validate method.</span>

<span class="sd">      :param path: file path to check</span>
<span class="sd">      :type path: string or unicode</span>
<span class="sd">      :param l: lenght</span>
<span class="sd">      :type l: int</span>
<span class="sd">      :returns: result, path, l</span>
<span class="sd">      :rtype: QtGui.QValidator.Acceptable or QtGui.QValidator.Intermediate,</span>
<span class="sd">              string or unicode, int</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">):</span>
      <span class="n">path</span><span class="p">,</span> <span class="n">selectedFilter</span> <span class="o">=</span> <span class="n">path</span>
    <span class="n">palette</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">()</span><span class="o">.</span><span class="n">palette</span><span class="p">()</span>

    <span class="k">if</span> <span class="n">QtCore</span><span class="o">.</span><span class="n">QFileInfo</span><span class="p">(</span><span class="n">path</span><span class="p">)</span><span class="o">.</span><span class="n">isFile</span><span class="p">():</span>
      <span class="n">palette</span><span class="o">.</span><span class="n">setColor</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QPalette</span><span class="o">.</span><span class="n">Base</span><span class="p">,</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QColor</span><span class="p">(</span><span class="s">&#39;white&#39;</span><span class="p">))</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">()</span><span class="o">.</span><span class="n">setPalette</span><span class="p">(</span><span class="n">palette</span><span class="p">)</span>
      <span class="n">result</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QValidator</span><span class="o">.</span><span class="n">Acceptable</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">palette</span><span class="o">.</span><span class="n">setColor</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QPalette</span><span class="o">.</span><span class="n">Base</span><span class="p">,</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QColor</span><span class="p">(</span><span class="s">&#39;SALMON&#39;</span><span class="p">))</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">()</span><span class="o">.</span><span class="n">setPalette</span><span class="p">(</span><span class="n">palette</span><span class="p">)</span>
      <span class="n">result</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QValidator</span><span class="o">.</span><span class="n">Intermediate</span>
    <span class="k">return</span> <span class="n">result</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">l</span>

<span class="c">#==============================================================================</span></div></div>
<div class="viewcode-block" id="FilePicker"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.FilePicker">[docs]</a><span class="k">class</span> <span class="nc">FilePicker</span><span class="p">(</span><span class="n">QtGui</span><span class="o">.</span><span class="n">QWidget</span><span class="p">):</span>
  <span class="sd">&quot;&quot;&quot; A File picker class</span>
<span class="sd">  &quot;&quot;&quot;</span>
  <span class="n">pathChanged</span> <span class="o">=</span> <span class="n">Signal</span><span class="p">(</span><span class="nb">str</span><span class="p">)</span>
  <span class="n">InputMode</span> <span class="o">=</span> <span class="mi">0</span>
  <span class="n">OutputMode</span> <span class="o">=</span> <span class="mi">1</span>

<div class="viewcode-block" id="FilePicker.__init__"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.FilePicker.__init__">[docs]</a>  <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">parent</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">pn</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">filt</span><span class="o">=</span><span class="s">u&#39;*&#39;</span><span class="p">,</span> <span class="n">extension</span><span class="o">=</span><span class="s">&#39;=&#39;</span><span class="p">,</span>
    <span class="n">mode</span><span class="o">=</span><span class="n">InputMode</span><span class="p">,</span> <span class="n">home</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">viewer</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">toolTip</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Create a new FileValidator instance.</span>

<span class="sd">      :param parent: parent widget</span>
<span class="sd">      :type parent: QtGui widget</span>
<span class="sd">      :param pn: optional pathname</span>
<span class="sd">      :type pn: valid pathname</span>
<span class="sd">      :param filt: file extension filter</span>
<span class="sd">      :type filt: string</span>
<span class="sd">      :param extension: extension to use for the viewer (default is full</span>
<span class="sd">                        pathname). *Valid only if viewer is defined.*</span>
<span class="sd">      :type extension: string</span>
<span class="sd">      :param mode: either :class:`InputMode` or :class`OutputMode`</span>
<span class="sd">      :type mode: int</span>
<span class="sd">      :param home: open picker in this directory</span>
<span class="sd">      :type home: string or unicode</span>
<span class="sd">      :param viewer: an optional file viewer class whose init accepts parent</span>
<span class="sd">                     and path keyword arguments</span>
<span class="sd">      :type viewer: class</span>
<span class="sd">      :param toolTip: An optional toolTip</span>
<span class="sd">      :type toolTip: string</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c"># Attributes</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_filter</span> <span class="o">=</span> <span class="n">filt</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_directory</span> <span class="o">=</span> <span class="n">home</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_viewer</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_ext</span> <span class="o">=</span> <span class="n">extension</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_path</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="k">if</span> <span class="n">viewer</span> <span class="o">==</span> <span class="s">&#39;default&#39;</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">viewerClass</span> <span class="o">=</span> <span class="n">FileBrowser</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">viewerClass</span> <span class="o">=</span> <span class="n">viewer</span>

    <span class="c"># Create the widget</span>
    <span class="nb">super</span><span class="p">(</span><span class="n">FilePicker</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
    <span class="c"># populate it</span>
    <span class="k">if</span> <span class="n">pn</span> <span class="ow">and</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">pn</span><span class="p">):</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QLineEdit</span><span class="p">(</span><span class="n">pn</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QLineEdit</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">_browse</span> <span class="o">=</span> <span class="n">TinyButton</span><span class="p">(</span><span class="s">u&quot;</span><span class="se">\N{DOWNWARDS DOUBLE ARROW}</span><span class="s">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>

    <span class="c"># Layout        </span>
    <span class="n">layout</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QHBoxLayout</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
    <span class="n">layout</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="p">)</span>
    <span class="n">layout</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_browse</span><span class="p">)</span>
    <span class="n">layout</span><span class="o">.</span><span class="n">setContentsMargins</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
    <span class="n">layout</span><span class="o">.</span><span class="n">setSpacing</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>

    <span class="c"># Signals</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">editingFinished</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">fileSelected</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_browse</span><span class="o">.</span><span class="n">clicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_selectFile</span><span class="p">)</span>

    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">viewerClass</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_viewBtn</span> <span class="o">=</span> <span class="n">TinyButton</span><span class="p">(</span><span class="s">u&quot;</span><span class="se">\N{LOWER RIGHT DROP-SHADOWED WHITE SQUARE}</span><span class="s">&quot;</span><span class="p">,</span>
        <span class="bp">self</span><span class="p">)</span>
      <span class="n">layout</span><span class="o">.</span><span class="n">addWidget</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_viewBtn</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_viewBtn</span><span class="o">.</span><span class="n">clicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_showFile</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_viewBtn</span> <span class="o">=</span> <span class="bp">None</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">setMode</span><span class="p">(</span><span class="n">mode</span><span class="p">,</span> <span class="n">toolTip</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="FilePicker.setMode"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.FilePicker.setMode">[docs]</a>  <span class="k">def</span> <span class="nf">setMode</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">mode</span><span class="p">,</span> <span class="n">toolTip</span><span class="o">=</span><span class="s">&#39;&#39;</span><span class="p">,</span> <span class="n">caption</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Set Widget mode: either :class:`InputMode` or :class:`OutputMode`</span>
<span class="sd">        A caption of None defaults to `mode`</span>

<span class="sd">      :param mode: either :class:`InputMode` or :class:`OutputMode`</span>
<span class="sd">      :type mode: int</span>
<span class="sd">      :param toolTip: An optional toolTip</span>
<span class="sd">      :type toolTip: string</span>
<span class="sd">      :param caption: optional caption</span>
<span class="sd">      :type caption: string or unicode</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">mode</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">InputMode</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_dialog</span> <span class="o">=</span> <span class="n">getOpenFileName</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_caption</span> <span class="o">=</span> <span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;filePicker&quot;</span><span class="p">,</span> <span class="s">&quot;Open file&quot;</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_browse</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;filePicker&quot;</span><span class="p">,</span>
        <span class="s">&quot;Click to select the input file&quot;</span><span class="p">))</span>
      <span class="k">if</span> <span class="n">toolTip</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;filePicker&quot;</span><span class="p">,</span>
          <span class="s">&quot;Enter here the name of the file to convert&quot;</span><span class="p">))</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">toolTip</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">setValidator</span><span class="p">(</span><span class="n">FileValidator</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_dialog</span> <span class="o">=</span> <span class="n">getSaveFileName</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_caption</span> <span class="o">=</span> <span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;filePicker&quot;</span><span class="p">,</span> <span class="s">&quot;Save to&quot;</span><span class="p">)</span>
      <span class="k">if</span> <span class="n">toolTip</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_browse</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;filePicker&quot;</span><span class="p">,</span>
          <span class="s">&quot;Click to select the output file&quot;</span><span class="p">))</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">toolTip</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">setToolTip</span><span class="p">(</span><span class="n">QCA</span><span class="o">.</span><span class="n">translate</span><span class="p">(</span><span class="s">&quot;filePicker&quot;</span><span class="p">,</span>
        <span class="s">&quot;Enter here the name of the output file&quot;</span><span class="p">))</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">setValidator</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">_mode</span> <span class="o">=</span> <span class="n">mode</span>
    <span class="k">if</span> <span class="n">caption</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_caption</span> <span class="o">=</span> <span class="n">caption</span>

    <span class="c"># Enable drops</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setAcceptDrops</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="FilePicker.dragEnterEvent"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.FilePicker.dragEnterEvent">[docs]</a>  <span class="k">def</span> <span class="nf">dragEnterEvent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">evt</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Reimplemented to tell the drag and drop system that we can only</span>
<span class="sd">        handle plain text</span>

<span class="sd">      :param evt: event</span>
<span class="sd">      :type evt: QtCore.QEvent</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">evt</span><span class="o">.</span><span class="n">mimeData</span><span class="p">()</span><span class="o">.</span><span class="n">hasUrls</span><span class="p">():</span>
      <span class="n">evt</span><span class="o">.</span><span class="n">accept</span><span class="p">()</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">evt</span><span class="o">.</span><span class="n">ignore</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="FilePicker.dropEvent"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.FilePicker.dropEvent">[docs]</a>  <span class="k">def</span> <span class="nf">dropEvent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">evt</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Reimplemented to copy the first dropped url into the editor</span>

<span class="sd">      :param evt: event</span>
<span class="sd">      :type evt: QtCore.QEvent</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">evt</span><span class="o">.</span><span class="n">mimeData</span><span class="p">()</span><span class="o">.</span><span class="n">hasUrls</span><span class="p">():</span>
      <span class="n">evt</span><span class="o">.</span><span class="n">setDropAction</span><span class="p">(</span><span class="n">QtCore</span><span class="o">.</span><span class="n">Qt</span><span class="o">.</span><span class="n">CopyAction</span><span class="p">)</span>
      <span class="n">evt</span><span class="o">.</span><span class="n">accept</span><span class="p">()</span>

      <span class="n">url</span> <span class="o">=</span> <span class="n">evt</span><span class="o">.</span><span class="n">mimeData</span><span class="p">()</span><span class="o">.</span><span class="n">urls</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
      <span class="n">pn</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">url</span><span class="o">.</span><span class="n">toLocalFile</span><span class="p">())</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="n">pn</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">fileSelected</span><span class="p">()</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">evt</span><span class="o">.</span><span class="n">ignore</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="FilePicker.text"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.FilePicker.text">[docs]</a>  <span class="k">def</span> <span class="nf">text</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Return text content</span>

<span class="sd">      :returns: text content</span>
<span class="sd">      :rtype: unicode</span>
<span class="sd">      :raises:</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="nb">unicode</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">text</span><span class="p">())</span>
</div>
  <span class="k">def</span> <span class="nf">_selectFile</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Select file using an appropriate dialog</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">options</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QFileDialog</span><span class="o">.</span><span class="n">DontUseNativeDialog</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">text</span><span class="p">():</span>
      <span class="n">absPath</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_directory</span>
    <span class="k">else</span><span class="p">:</span>
      <span class="n">absPath</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">text</span><span class="p">())</span>
    <span class="n">fileName</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_dialog</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_caption</span><span class="p">,</span> <span class="n">absPath</span><span class="p">,</span>
      <span class="nb">filter</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_filter</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="n">options</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">fileName</span><span class="p">:</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="n">fileName</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">fileSelected</span><span class="p">()</span>

<div class="viewcode-block" id="FilePicker.fileSelected"><a class="viewcode-back" href="../../ccqw.html#ccqw.filePicker.FilePicker.fileSelected">[docs]</a>  <span class="k">def</span> <span class="nf">fileSelected</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; File has been selected: emit the Signal</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_path</span> <span class="o">!=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">text</span><span class="p">():</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">text</span><span class="p">()</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">pathChanged</span><span class="o">.</span><span class="n">emit</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_path</span><span class="p">)</span>
</div>
  <span class="k">def</span> <span class="nf">_showFile</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; Show ascii file in a viewer</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">text</span><span class="p">():</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_viewer</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_viewer</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
      <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ext</span> <span class="o">==</span> <span class="s">&#39;=&#39;</span><span class="p">:</span>
        <span class="n">path</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">text</span><span class="p">())</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="n">path</span> <span class="o">=</span> <span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_editor</span><span class="o">.</span><span class="n">text</span><span class="p">()))[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ext</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_viewer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">viewerClass</span><span class="p">(</span><span class="n">parent</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_viewBtn</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="n">path</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_viewer</span><span class="o">.</span><span class="n">resize</span><span class="p">(</span><span class="mi">640</span><span class="p">,</span> <span class="mi">480</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_viewer</span><span class="o">.</span><span class="n">setWindowTitle</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">path</span><span class="p">)</span>
      <span class="bp">self</span><span class="o">.</span><span class="n">_viewer</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>

<span class="c">#==============================================================================</span></div>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;__main__&quot;</span><span class="p">:</span>
  <span class="kn">import</span> <span class="nn">sys</span>
  <span class="kn">import</span> <span class="nn">signal</span>
  <span class="n">signal</span><span class="o">.</span><span class="n">signal</span><span class="p">(</span><span class="n">signal</span><span class="o">.</span><span class="n">SIGINT</span><span class="p">,</span> <span class="n">signal</span><span class="o">.</span><span class="n">SIG_DFL</span><span class="p">)</span>

  <span class="n">app</span> <span class="o">=</span> <span class="n">QtGui</span><span class="o">.</span><span class="n">QApplication</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span>
  <span class="n">f</span> <span class="o">=</span> <span class="n">FilePicker</span><span class="p">(</span><span class="n">pn</span><span class="o">=</span><span class="n">__file__</span><span class="p">,</span> <span class="n">home</span><span class="o">=</span><span class="n">QtCore</span><span class="o">.</span><span class="n">QDir</span><span class="o">.</span><span class="n">homePath</span><span class="p">(),</span>
    <span class="n">filt</span><span class="o">=</span><span class="s">&#39;Python modules (*.py)&#39;</span><span class="p">,</span> <span class="n">viewer</span><span class="o">=</span><span class="s">&#39;default&#39;</span><span class="p">)</span>
  <span class="c">#f = FilePicker(home=QtCore.QDir.homePath())</span>
  <span class="n">f</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
  <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">exec_</span><span class="p">())</span>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/ogs.png" alt="Logo"/>
            </a></p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">CCQW 0.1.1 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, Roberto Vidmar, Nicola Creati.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
    </div>
  </body>
</html>